package com.obas.business.common.support;

public abstract class PaginationHandlerCallback {

	public static final int TASK_PAGINATION_SIZE = 500;

	public abstract int count();

	public abstract void onPagination(int paginationIndex);

	public void handle() {
		int count = count();
		
		if (count > 0) {
			int pages = count / TASK_PAGINATION_SIZE + (count % TASK_PAGINATION_SIZE == 0 ? 0 : 1);
			for (int i = 1; i <= pages; i++) {
				final int paginationIndex = i;
				onPagination(paginationIndex);
			}
		}
	}

}
